package com.yihaodian.cluster.discovery;

import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
import com.yihaodian.cluster.Node;
import com.yihaodian.cluster.discovery.zk.ZkNodeDiscovery;
import com.yihaodian.zk.ZkClient;
import com.yihaodian.zk.ZkClientService;

public class DiscoveryModule extends AbstractModule {
	String zkQuorums = null;
	String zkRootPath = null;
	Node node = null;

	public DiscoveryModule(String zkQuorums, String zkRootPath, Node node) {
		// TODO pass setting
		this.zkQuorums = zkQuorums;
		this.zkRootPath = zkRootPath;
		this.node = node;
	}

	@Override
	protected void configure() {
		bindConstant().annotatedWith(Names.named("zkQuorums")).to(zkQuorums);
		bind(ZkClient.class).to(ZkClientService.class).asEagerSingleton();

		bind(Node.class).toInstance(node);
		bindConstant().annotatedWith(Names.named("zkRootPath")).to(zkRootPath);
		bind(NodeDiscovery.class).to(ZkNodeDiscovery.class).asEagerSingleton();
	}
}
